package com.ai_chat.sys.controller;

import com.ai_chat.common.vo.Result;
import com.ai_chat.sys.entity.TokenPackage;
import com.ai_chat.sys.service.impl.TokenPackageServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@RestController
@CrossOrigin
@RequestMapping("/tokenPackage")
public class TokenPackageController {
    @Autowired
    private TokenPackageServiceImpl tokenPackageService;

    @GetMapping("/getAllTokenPackage")
    public Result<List<Map<String,Object>>> getAllTokenPackage(){

        List<TokenPackage> tokenPackagesList = tokenPackageService.getAllTokenPackage();
        List<Map<String,Object>> data = new ArrayList<>();
        for (TokenPackage tp : tokenPackagesList){
            Map<String,Object> map = new HashMap<>();
                map.put("id", tp.getId());
                map.put("name", tp.getPackageName());
                map.put("price", tp.getPackagePrice());
                map.put("token", tp.getPackageToken());

            data.add(map);
        }
        return Result.success(data);
    }
}
